package com.ruoyi.domain.base;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.file.FileReader;
import cn.hutool.core.io.resource.ClassPathResource;
import cn.hutool.json.JSONObject;
import cn.hutool.json.XML;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;

import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.List;

public class BmxxInstance {

    private static volatile List<Bmxx> list;

    static {
        readFileData();
    }

    private static void readFileData() {
        ClassPathResource classPathResource = new ClassPathResource("classpath:invoice/spbm.xml");
//        FileReader fileReader = new FileReader(classPathResource.getFile(), Charset.forName("gbk"));
        InputStream stream = classPathResource.getStream();
//        FileReader fileReader = new FileReader()
        String result = IoUtil.read(stream,Charset.forName("gbk"));
        JSONObject jsonObject = XML.toJSONObject(result);
        list = jsonObject.getJSONObject("business").getJSONObject("body").getBeanList("BMXX", Bmxx.class);
    }

    public static List<Bmxx> getList() {
        if (list == null) {
            synchronized (BmxxInstance.class) {
                if (list == null) {
                    readFileData();
                }
            }
        }
        return list;
    }

}
